home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0238_Backgrounds on Delphi forms.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-05-30  |  914 b   |  28 lines

  1.  
  2. Windows, web pages, multimedia programs, etc. have backgrounds. How come your Delphi
  3. form doesn't?
  4. --------------------------------------------------------------------------------
  5. Of course you could place an Image component on your form and set it's Alignment
  6. to Client to place a background on your form. But, here's another way to do it:
  7.  
  8. (1) Add following to your form's Public declarations section:
  9.  
  10.     bmpBackground : TBitmap;
  11.  
  12. (2) Double click on your form and add bitmap initialization code to the
  13. FormCreate procedure:
  14.  
  15.     bmpBackground := TBitmap.Create;
  16.     bmpBackground.LoadFromFile( 'c:\windows\setup.bmp' );
  17.  
  18. (3) Go to the form's events list and double click on OnPaint. Add following
  19. line to the FormPaint procedure:
  20.  
  21.     Canvas.Draw( 0, 0, bmpBackground );
  22.  
  23. (4) Finally insert the following code to FormDestroy
  24. procedure (OnDestroy event):
  25.  
  26.     bmpBackground.Free;
  27.  
  28.